#include <vector>
#include <iostream>
const int N = 1E6 + 5;
using namespace std;
using ll = long long int;
int main()
{
    int n;
    cin >> n;
    ll ret = 0x3f3f3f3f3f3f3f3f;
    ll dp[N];
    dp[0] = 0;
    dp[1] = 1;
    int i=2;
    for ( i = 2; i <= n; i++)
    {
        dp[i] = dp[i - 1] + dp[i - 2];
        if(dp[i]>n) break;
        // cout<<dp[i]<<endl;
    }
    // 找最接近我们的n的数字
    int numsmin = -1, numsmax = -1;
    int left = 0, right = i;
    while (left <= right)
    {
        int mid = (right - left) / 2 + left;
        if (dp[mid] >= n)
        {
            numsmax = dp[mid];
            right = mid - 1;
        }
        else
        {
            left = mid + 1;
        }
    }
    // cout<<"--------------------"<<endl;
    // cout<<numsmax<<endl;
    left = 0, right = i;
    while (left <= right)
    {
        int mid = (right - left) / 2 + left;
        if (dp[mid] <= n)
        {
            numsmin = dp[mid];
            left = mid + 1;
        }
        else
        {
            right = mid - 1;
        }
    }
    if(numsmax!=-1) ret=min(ret,(ll)abs(numsmax-n));
    if(numsmin!=-1) ret=min(ret,(ll)abs(numsmin-n));
    cout<<ret;
    return 0;
}